Shader "Level4/Progress/SimpleProgress" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_Mask("Mask",2d) = ""{}
		_Progress("Progress",range(0,1)) = 0.4
		_ProgressColor("Progress Color",color) = (1,0,0,0)
		_CompleteColor("Complete Color",color) = (0,1,0,0)
	}
	
	CGINCLUDE
		#include "UnityCG.cginc"
		sampler2D _MainTex;
		sampler2D _Mask;
		float _Progress;
		half4 _ProgressColor;
		half4 _CompleteColor;
		
		struct v2f{
			half4 pos:POSITION;
			half2 uv:TEXCOORD;
		};
		
		v2f vert(appdata_base i){
			v2f v;
			v.pos = mul(UNITY_MATRIX_MVP,i.vertex);
			v.uv = i.texcoord;
			return v;
		}
		
		half4 frag(v2f i):COLOR{
			half4 m = tex2D(_Mask,i.uv);
			clip(_Progress - m.a);
			if(m.a == 0)
				clip(-1);
			half4 c = tex2D(_MainTex,i.uv);
			c *= _Progress < 0.9999? _ProgressColor : _CompleteColor;
			return c;
		}
	ENDCG
	
	SubShader {
		Tags { "RenderType"="Transparent" }
		LOD 400
		Blend one OneMinusSrcAlpha
		Pass{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			ENDCG
		}
	}
	FallBack "Diffuse"
}
